package com.wanmait.zaisousuo.service.Impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.zaisousuo.mapper.DataMapper;
import com.wanmait.zaisousuo.pojo.Data;
import com.wanmait.zaisousuo.service.CompanyDataService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.wanmait.zaisousuo.mapper.CompanyDataMapper;
import com.wanmait.zaisousuo.pojo.CompanyData;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CompanyDataServiceImpl implements CompanyDataService {

    @Resource
    CompanyDataMapper companyDataMapper;
    @Resource
    DataMapper dataMapper;

    //企业用户添加数据
    @Override
    public void insert(CompanyData companyData) {
     companyDataMapper.insert(companyData);
    }

    @Override
    public void update(CompanyData object) {

    }

    //彻底删除一条数据
    @Override
    public void delete(Integer id) {
       companyDataMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public CompanyData findById(Integer id) {
        return null;
    }

    //查询出所有数据
    @Cacheable(value = "CompanyDataCache",key = "'findAllCompanyData'")
    @Override
    public List<CompanyData> findAll() {
        return companyDataMapper.findAll();
    }

    @Override
    public List<CompanyData> findAll(CompanyData object) {
        return null;
    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public int getDataCount(CompanyData object) {
        return 0;
    }

    @Override
    public PageInfo<CompanyData> findList(int pageNum) {
        return null;
    }

    //改变数据审核状态
    @Override
    public String changeStateById(Boolean flag, Integer id) {
        companyDataMapper.changeStateById(flag,id);
        return id+"&split&"+flag;
    }

    //某一种垃圾对应城市的回收量
    @Cacheable(value = "CompanyDataCache",key = "'getDataByCityId'+#cityId+'id='+#id")
    @Override
    public Data getDataByCityId(Integer cityId, Integer id) {
        return dataMapper.getDataByCityId(cityId,id);
    }

    //企业用户添加、后台删除、后台更改审核状态：清空查询全部的缓存
    @CacheEvict(value = "CompanyDataCache",key = "'findAllCompanyData'")
    @Override
    public void clearFindAllCompanyDataCache(){}

}
